package com.cn.unarmed.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

/**
 * Created by Administrator on 2017/6/27.
 */
public class LittleBall extends View {

    public float currentX = 40;//当前小球横坐标
    public float currentY = 50;//当前小球纵坐标

    Paint p = new Paint();//定义并创建画笔

    public LittleBall(Context context){
        super(context);
    }

    public LittleBall(Context context, AttributeSet set){
        super(context,set);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //设置画笔的颜色
        p.setColor(Color.RED);
        //绘制一个小圆
        canvas.drawCircle(currentX,currentY,15,p);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        //获取出没位置更改小球的横纵坐标
        currentX = event.getX();
        currentY = event.getY();
        //通知组件更新
        invalidate();
        return true;
    }
}
